package com.example.lastwork.controller;


import com.example.lastwork.common.controller.LogicController;
import com.example.lastwork.dao.BusinessDao;
import com.example.lastwork.dto.RestDTO;
import com.example.lastwork.entity.Business;
import com.example.lastwork.entity.Shop;
import com.example.lastwork.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "商家服务接口")
@RestController
@RequestMapping("/BusinessController")
public class BusinessController extends LogicController<BusinessService, BusinessDao, Business, Long> {
    public BusinessController(@Autowired BusinessService service){
        super(service);
    }

    @ApiOperation("创建门店")
    @RequestMapping(value = "/createShop",method = RequestMethod.POST)
    public RestDTO<Shop> createShop(@ApiParam("商家编号") Long businessId, @ApiParam("门店名称") String shopName){
        return RestDTO.success(getService().createShop(businessId, shopName));
    }

    @ApiOperation("新建商品")
    @RequestMapping(value = "/createShopItem",method = RequestMethod.POST)
    public RestDTO<String> createItem(@ApiParam("商家编号") Long businessId, @ApiParam("商家商品名称") String itemName,
                                      @ApiParam("商品价格") Double price, @ApiParam("商店编号") Long shopId,
                                      @ApiParam("商品国标码") Long itemId){
        return RestDTO.success(getService().createItem(businessId, itemName, price,shopId,itemId));
    }

    @ApiOperation("确认已支付的订单")
    @RequestMapping(value = "/confirmOrder",method = RequestMethod.POST)
    public RestDTO<String> confirmOrder(@ApiParam("订单编号") Long ordersId){
        return RestDTO.success(getService().confirmOrder(ordersId));
    }

    @ApiOperation("取消已支付的订单")
    @RequestMapping(value = "/refundOrder",method = RequestMethod.POST)
    public RestDTO<String> refundOrder(@ApiParam("订单编号") Long ordersId){
        return RestDTO.success(getService().refundOrder(ordersId));
    }
}
